package pe.com.cotelasa.scp.entidad;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlTransient;

@Entity
@Table(name = "sede", catalog = "bdcotelasa", schema = "cotelasa")
@NamedQueries({
		@NamedQuery(name = "Sede.findAll", query = "SELECT s FROM Sede s"),
		@NamedQuery(name = "Sede.findById", query = "SELECT s FROM Sede s WHERE s.id = :id"),
		@NamedQuery(name = "Sede.findByNombre", query = "SELECT s FROM Sede s WHERE s.nombre = :nombre"),
		@NamedQuery(name = "Sede.findByDescripcion", query = "SELECT s FROM Sede s WHERE s.descripcion = :descripcion"),
		@NamedQuery(name = "Sede.findBySedeAdministradora", query = "SELECT s FROM Sede s WHERE s.sedeAdministradora = :sedeAdministradora"),
		@NamedQuery(name = "Sede.findByDireccion", query = "SELECT s FROM Sede s WHERE s.direccion = :direccion"),
		@NamedQuery(name = "Sede.findByDescUbicacion", query = "SELECT s FROM Sede s WHERE s.descUbicacion = :descUbicacion"),
		@NamedQuery(name = "Sede.findByReferencia", query = "SELECT s FROM Sede s WHERE s.referencia = :referencia"),
		@NamedQuery(name = "Sede.findByEsTienda", query = "SELECT s FROM Sede s WHERE s.esTienda = :esTienda"),
		@NamedQuery(name = "Sede.findByEsAlmacen", query = "SELECT s FROM Sede s WHERE s.esAlmacen = :esAlmacen"),
		@NamedQuery(name = "Sede.findByEstadoRegistro", query = "SELECT s FROM Sede s WHERE s.estadoRegistro = :estadoRegistro"),
		@NamedQuery(name = "Sede.findByUsrCreacion", query = "SELECT s FROM Sede s WHERE s.usrCreacion = :usrCreacion"),
		@NamedQuery(name = "Sede.findByFecCreacion", query = "SELECT s FROM Sede s WHERE s.fecCreacion = :fecCreacion"),
		@NamedQuery(name = "Sede.findByUsrModificacion", query = "SELECT s FROM Sede s WHERE s.usrModificacion = :usrModificacion"),
		@NamedQuery(name = "Sede.findByFecModificacion", query = "SELECT s FROM Sede s WHERE s.fecModificacion = :fecModificacion") })
public class Sede implements Serializable {

	private static final long serialVersionUID = 2181989917910488047L;

	@Id
	@SequenceGenerator(name = "generadorSede", sequenceName = "cotelasa.sede_id_seq")
	@GeneratedValue(generator = "generadorSede")
	@Basic(optional = false)
	@Column(name = "id")
	private Integer id;
        
	@Basic(optional = false)
	@Column(name = "nombre")
	private String nombre;
        
	@Column(name = "descripcion")
	private String descripcion;
        
	@Basic(optional = false)
	@Column(name = "sede_administradora")
	private int sedeAdministradora;
        
	@Basic(optional = false)
	@Column(name = "direccion")
	private String direccion;
        
	@Column(name = "desc_ubicacion")
	private String descUbicacion;
        
	@Column(name = "referencia")
	private String referencia;
        
        @Column(name = "recurso_impresora")
	private String recursoImpresora;
	
	@Column(name = "nro_sec_guia_remision")
	private Integer nroSecGuiaRemision;
    
	@Column(name = "nro_serie_guia_remision")
	private String nroSerieGuiaRemision;
 
	@Column(name = "nro_sec_factura")
	private Integer nroSecFactura;
	    
	@Column(name = "nro_serie_factura")
	private String nroSerieFactura;
        
	@Basic(optional = false)
	@Column(name = "es_tienda")
	private Short esTienda;
        
	@Basic(optional = false)
	@Column(name = "es_almacen")
	private Short esAlmacen;
        
	@Basic(optional = false)
	@Column(name = "estado_registro")
	private char estadoRegistro;
        
	@Basic(optional = false)
	@Column(name = "usr_creacion")
	private String usrCreacion;
        
	@Basic(optional = false)
	@Column(name = "fec_creacion")
	@Temporal(TemporalType.TIMESTAMP)
	private Date fecCreacion;
        
	@Column(name = "usr_modificacion")
	private String usrModificacion;
        
	@Column(name = "fec_modificacion")
	@Temporal(TemporalType.TIMESTAMP)
	private Date fecModificacion;
	
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "idSede", fetch = FetchType.LAZY)
	private Collection<Contacto> contactoCollection;
	
	@JoinColumn(name = "id_ubigeo", referencedColumnName = "id")
	@ManyToOne(optional = false, fetch = FetchType.LAZY)
	private Ubigeo idUbigeo;
	
	@JoinColumn(name = "id_proveedor", referencedColumnName = "id")
	@ManyToOne(fetch = FetchType.LAZY)
	private Proveedor idProveedor;
	
        @JoinColumn(name = "id_cliente", referencedColumnName = "id")
	@ManyToOne(fetch = FetchType.LAZY)
	private Cliente idCliente;
        
	@JoinColumn(name = "id_empresa", referencedColumnName = "id")
	@ManyToOne(fetch = FetchType.LAZY)
	private Empresa idEmpresa;
	
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "idSede")
	private Collection<CajaChica> cajaChicaCollection;
        
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "idsede")
	private Collection<CorrelativoDocumento> correlativoDocumentoCollection;
        
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "sede")
        private Collection<Kardex> kardexCollection;
        
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "sede")
        private Collection<ArticuloSede> articuloSedeCollection;
        
	// bi-directional many-to-one association to GuiaRemision
	@OneToMany(mappedBy = "sedeLlegada", fetch = FetchType.LAZY)
	private List<GuiaRemision> guiaRemisionsLlegada;

	// bi-directional many-to-one association to GuiaRemision
	@OneToMany(mappedBy = "sedePartida", fetch = FetchType.LAZY)
	private List<GuiaRemision> guiaRemisionsPartida;
        
	public Sede() {
		//this.idEmpresa = new Empresa();
	}

	public Sede(Integer id) {
		this.id = id;
	}

	public Sede(Integer id, String nombre, int sedeAdministradora,
			String direccion, Short esTienda, Short esAlmacen,
			char estadoRegistro, String usrCreacion, Date fecCreacion) {
		this.id = id;
		this.nombre = nombre;
		this.sedeAdministradora = sedeAdministradora;
		this.direccion = direccion;
		this.esTienda = esTienda;
		this.esAlmacen = esAlmacen;
		this.estadoRegistro = estadoRegistro;
		this.usrCreacion = usrCreacion;
		this.fecCreacion = fecCreacion;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNombre() {
		return nombre;
	}

	public void setNombre(String nombre) {
		this.nombre = nombre;
	}

	public String getDescripcion() {
		return descripcion;
	}

	public void setDescripcion(String descripcion) {
		this.descripcion = descripcion;
	}

	public int getSedeAdministradora() {
		return sedeAdministradora;
	}

	public void setSedeAdministradora(int sedeAdministradora) {
		this.sedeAdministradora = sedeAdministradora;
	}

	public String getDireccion() {
		return direccion;
	}

	public void setDireccion(String direccion) {
		this.direccion = direccion;
	}

	public String getReferencia() {
		return referencia;
	}

	public void setReferencia(String referencia) {
		this.referencia = referencia;
	}

	public Short getEsTienda() {
		return esTienda;
	}

	public void setEsTienda(Short esTienda) {
		this.esTienda = esTienda;
	}

	public Short getEsAlmacen() {
		return esAlmacen;
	}

	public void setEsAlmacen(Short esAlmacen) {
		this.esAlmacen = esAlmacen;
	}

	public char getEstadoRegistro() {
		return estadoRegistro;
	}

	public void setEstadoRegistro(char estadoRegistro) {
		this.estadoRegistro = estadoRegistro;
	}

	public String getUsrCreacion() {
		return usrCreacion;
	}

	public void setUsrCreacion(String usrCreacion) {
		this.usrCreacion = usrCreacion;
	}

	public Date getFecCreacion() {
		return fecCreacion;
	}

	public void setFecCreacion(Date fecCreacion) {
		this.fecCreacion = fecCreacion;
	}

	public String getUsrModificacion() {
		return usrModificacion;
	}

	public void setUsrModificacion(String usrModificacion) {
		this.usrModificacion = usrModificacion;
	}

	public Date getFecModificacion() {
		return fecModificacion;
	}

	public void setFecModificacion(Date fecModificacion) {
		this.fecModificacion = fecModificacion;
	}

	public Collection<Contacto> getContactoCollection() {
		return contactoCollection;
	}

	public void setContactoCollection(Collection<Contacto> contactoCollection) {
		this.contactoCollection = contactoCollection;
	}

	public Ubigeo getIdUbigeo() {
		return idUbigeo;
	}

	public void setIdUbigeo(Ubigeo idUbigeo) {
		this.idUbigeo = idUbigeo;
	}

	public Proveedor getIdProveedor() {
		return idProveedor;
	}

	public void setIdProveedor(Proveedor idProveedor) {
		this.idProveedor = idProveedor;
	}

	public Empresa getIdEmpresa() {
		return idEmpresa;
	}

	public void setIdEmpresa(Empresa idEmpresa) {
		this.idEmpresa = idEmpresa;
	}

	public Cliente getIdCliente() {
		return idCliente;
	}

	public void setIdCliente(Cliente idCliente) {
		this.idCliente = idCliente;
	}

	public Collection<CajaChica> getCajaChicaCollection() {
		return cajaChicaCollection;
	}

	public void setCajaChicaCollection(Collection<CajaChica> cajaChicaCollection) {
		this.cajaChicaCollection = cajaChicaCollection;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are
		// not set
		if (!(object instanceof Sede)) {
			return false;
		}
		Sede other = (Sede) object;
		if ((this.id == null && other.id != null)
				|| (this.id != null && !this.id.equals(other.id))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "pe.com.cotelasa.scp.entidad.Sede[ id=" + id + " ]";
	}

	public String getDescUbicacion() {
		return descUbicacion;
	}

	public void setDescUbicacion(String descUbicacion) {
		this.descUbicacion = descUbicacion;
	}

	public List<GuiaRemision> getGuiaRemisionsLlegada() {
		return guiaRemisionsLlegada;
	}

	public void setGuiaRemisionsLlegada(List<GuiaRemision> guiaRemisionsLlegada) {
		this.guiaRemisionsLlegada = guiaRemisionsLlegada;
	}

	public List<GuiaRemision> getGuiaRemisionsPartida() {
		return guiaRemisionsPartida;
	}

	public void setGuiaRemisionsPartida(List<GuiaRemision> guiaRemisionsPartida) {
		this.guiaRemisionsPartida = guiaRemisionsPartida;
	}

	public Integer getNroSecGuiaRemision() {
		return nroSecGuiaRemision;
	}

	public void setNroSecGuiaRemision(Integer nroSecGuiaRemision) {
		this.nroSecGuiaRemision = nroSecGuiaRemision;
	}

	public String getNroSerieGuiaRemision() {
		return nroSerieGuiaRemision;
	}

	public void setNroSerieGuiaRemision(String nroSerieGuiaRemision) {
		this.nroSerieGuiaRemision = nroSerieGuiaRemision;
	}
	
	public Integer getNroSecFactura() {
		return nroSecFactura;
	}

	public void setNroSecFactura(Integer nroSecFactura) {
		this.nroSecFactura = nroSecFactura;
	}

	public String getNroSerieFactura() {
		return nroSerieFactura;
	}

	public void setNroSerieFactura(String nroSerieFactura) {
		this.nroSerieFactura = nroSerieFactura;
	}

    public Collection<CorrelativoDocumento> getCorrelativoDocumentoCollection() {
        return correlativoDocumentoCollection;
    }

    public void setCorrelativoDocumentoCollection(Collection<CorrelativoDocumento> correlativoDocumentoCollection) {
        this.correlativoDocumentoCollection = correlativoDocumentoCollection;
    }


    @XmlTransient
    public Collection<Kardex> getKardexCollection() {
        return kardexCollection;
    }

    public void setKardexCollection(Collection<Kardex> kardexCollection) {
        this.kardexCollection = kardexCollection;
    }

    public Collection<ArticuloSede> getArticuloSedeCollection() {
        return articuloSedeCollection;
    }

    public void setArticuloSedeCollection(Collection<ArticuloSede> articuloSedeCollection) {
        this.articuloSedeCollection = articuloSedeCollection;
    }

    public String getRecursoImpresora() {
        return recursoImpresora;
    }

    public void setRecursoImpresora(String recursoImpresora) {
        this.recursoImpresora = recursoImpresora;
    }


    }
